Boyer-Moore Search
Definition:
Boyer-Moore Search is a string-search algorithm that skips sections of text to improve efficiency, making it highly effective for long text searches. It relies on two heuristics—bad character rule and good suffix rule—to skip sections that don’t match, enabling faster matching.
Characteristics:
- String Matching: Efficient for matching strings in long texts.
- Heuristic-Based Skipping: Uses heuristics to skip mismatching sections.
- Backward Matching: Compares the pattern from right to left.
Video Explanation

How Boyer-Moore Works:
- Initialize: Place pattern at the start of the text.
- Compare Backwards: Match the pattern from right to left.
- Skip: Use heuristics to skip mismatching sections.
- Repeat: Continue until the pattern is found or text is exhausted.
Time Complexity:
- Best Case: (O(n/m)), where
nis the length of the text andmis the length of the pattern. - Worst Case: (O(n \times m))